<template>
  <div class="app-container">
    <basic-container  v-show="showSearch">
      <common-search @handleQuery="handleQuery" @resetQuery="resetQuery">
        <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="100px">
          <el-form-item label="集装箱号" prop="contaNo">
            <el-input
              v-model="queryParams.contaNo"
              placeholder="请输入集装箱号"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="审核状态" prop="declStatus">
            <el-select v-model="queryParams.declStatus" placeholder="请选择审核状态" clearable size="small">
              <el-option
                v-for="dict in dict.type.conta_decl_status"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
        </el-form>
      </common-search>
    </basic-container>

    <basic-container>
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
            v-hasPermi="['billsdecl:contaRecord:add']"
          >新增</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="success"
            plain
            icon="el-icon-edit"
            size="mini"
            :disabled="single"
            @click="handleUpdate"
            v-hasPermi="['billsdecl:contaRecord:edit']"
          >修改</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="danger"
            plain
            icon="el-icon-delete"
            size="mini"
            :disabled="multiple"
            @click="handleDelete"
            v-hasPermi="['billsdecl:contaRecord:remove']"
          >删除</el-button>
        </el-col>
      <!-- <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            :loading="exportLoading"
            @click="handleExport"
            v-hasPermi="['billsdecl:contaRecord:export']"
          >导出</el-button>
        </el-col>
        -->
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>

      <el-table v-loading="loading" :data="contaRecordList" @selection-change="handleSelectionChange" @row-dblclick="showDetail" stripe border>
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="主键" align="center" prop="id" />
        <el-table-column label="场所代码" align="center" prop="fieldCode" min-width="100" />
        <el-table-column label="场所名称" align="center" prop="fieldName" min-width="100" />
        <el-table-column label="集装箱号" align="center" prop="contaNo" min-width="100" />
        <el-table-column label="集装箱重量" align="center" prop="contaWt" min-width="100" />
        <el-table-column label="集装箱类型" align="center" prop="contaType" min-width="100" />
        <el-table-column label="集装箱尺寸" align="center" prop="contaSize" min-width="100" />
        <el-table-column label="集装箱代码" align="center" prop="contaCode" min-width="100" />
        <el-table-column show-overflow-tooltip label="中文集装箱规格名称" align="center" prop="cnContaSpec" min-width="100" />
        <el-table-column label="申报人" align="center" prop="declBy" min-width="100" />
        <el-table-column label="申报时间" align="center" prop="declTime" min-width="100">
        </el-table-column>
        <el-table-column show-overflow-tooltip label="申报重试次数，超过3分钟未回执，会自动再次发起申报，超过10次不在重试" align="center" prop="declRetryNum" min-width="120">
        </el-table-column>
        <el-table-column label="审核时间" align="center" prop="auditDate" width="180">
        </el-table-column>
        <el-table-column label="创建者" align="center" prop="createBy" />
        <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        </el-table-column>
        <el-table-column label="备注" align="center" prop="remark" />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-view"
              @click="showDetail(scope.row)"
              v-hasPermi="['billsdecl:contaRecord:query']"
            >详情</el-button>
            
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['billsdecl:contaRecord:edit']"
            >修改</el-button>
            
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
              v-hasPermi="['billsdecl:contaRecord:remove']"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </basic-container>


    <!-- 添加或修改集装箱备案对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body :close-on-click-modal="false">
      <el-form ref="form" :model="form" :rules="rules" label-width="80px"  :disabled="isViewDisabled">
          <el-row>  
       		<el-col :span="12">
		        <el-form-item label="场所代码" prop="fieldCode">
		          <el-input v-model="form.fieldCode" placeholder="请输入场所代码" />
		        </el-form-item>
       		</el-col>
       		<el-col :span="12">
		        <el-form-item label="场所名称" prop="fieldName">
		          <el-input v-model="form.fieldName" placeholder="请输入场所名称" />
		        </el-form-item>
       		</el-col>
	  </el-row>
         <el-row>
       		<el-col :span="12">
		        <el-form-item label="集装箱号" prop="contaNo">
		          <el-input v-model="form.contaNo" placeholder="请输入集装箱号" />
		        </el-form-item>
       		</el-col>
       		<el-col :span="12">
		        <el-form-item label="集装箱重量" prop="contaWt">
		          <el-input v-model="form.contaWt" placeholder="请输入集装箱重量" />
		        </el-form-item>
       		</el-col>
	  </el-row>
         <el-row>
       		<el-col :span="12">
		        <el-form-item label="集装箱类型" prop="contaType">
		          <el-select v-model="form.contaType" placeholder="请选择集装箱类型">
		            <el-option label="请选择字典生成" value="" />
		          </el-select>
		        </el-form-item>
       		</el-col>
       		<el-col :span="12">
		        <el-form-item label="集装箱尺寸" prop="contaSize">
		          <el-input v-model="form.contaSize" placeholder="请输入集装箱尺寸" />
		        </el-form-item>
       		</el-col>
	  </el-row>
         <el-row>
       		<el-col :span="12">
		        <el-form-item label="集装箱代码" prop="contaCode">
		          <el-input v-model="form.contaCode" placeholder="请输入集装箱代码" />
		        </el-form-item>
       		</el-col>
       		<el-col :span="12">
		        <el-form-item label="中文集装箱规格名称" prop="cnContaSpec">
		          <el-input v-model="form.cnContaSpec" placeholder="请输入中文集装箱规格名称" />
		        </el-form-item>
       		</el-col>
	  </el-row>
         <el-row>
       		<el-col :span="12">
		        <el-form-item label="申报人" prop="declBy">
		          <el-input v-model="form.declBy" placeholder="请输入申报人" />
		        </el-form-item>
       		</el-col>
       		<el-col :span="12">
		        <el-form-item label="申报时间" prop="declTime">
		          <el-date-picker clearable size="small"
		            v-model="form.declTime"
		            type="date"
		            value-format="yyyy-MM-dd HH:mm:ss"
		            placeholder="选择申报时间">
		          </el-date-picker>
		        </el-form-item>
       		</el-col>
	  </el-row>
         <el-row>
       		<el-col :span="12">
		        <el-form-item label="审核状态" prop="declStatus">
		          <el-select v-model="form.declStatus" placeholder="请选择审核状态">
		            <el-option
		              v-for="dict in dict.type.conta_decl_status"
		              :key="dict.value"
		              :label="dict.label"
		              :value="dict.value"		            ></el-option>
		          </el-select>
		        </el-form-item>
       		</el-col>
       		<el-col :span="12">
		        <el-form-item label="申报重试次数，超过3分钟未回执，会自动再次发起申报，超过10次不在重试" prop="declRetryNum">
		          <el-input v-model="form.declRetryNum" placeholder="请输入申报重试次数，超过3分钟未回执，会自动再次发起申报，超过10次不在重试" />
		        </el-form-item>
       		</el-col>
	  </el-row>
         <el-row>
       		<el-col :span="12">
		        <el-form-item label="审核时间" prop="auditDate">
		          <el-date-picker clearable size="small"
		            v-model="form.auditDate"
		            type="date"
		            value-format="yyyy-MM-dd HH:mm:ss"
		            placeholder="选择审核时间">
		          </el-date-picker>
		        </el-form-item>
       		</el-col>
	  </el-row>
         <el-row>
	  </el-row>
         <el-row>
       		<el-col :span="12">
		        <el-form-item label="备注" prop="remark">
		          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
		        </el-form-item>
       		</el-col>
	   </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" v-if="!isViewDisabled">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 详情dialog-->
    <el-dialog :visible.sync="detailOpen" width="50%" append-to-body :close-on-click-modal="false">
       <el-descriptions class="margin-top" title="集装箱备案详情" :column="3"  border>
		 <el-descriptions-item>
		        <template slot="label">
		         场所代码
		        </template>
		       {{form.fieldCode}}
		  </el-descriptions-item>
		 <el-descriptions-item>
		        <template slot="label">
		         场所名称
		        </template>
		       {{form.fieldName}}
		  </el-descriptions-item>
		 <el-descriptions-item>
		        <template slot="label">
		         集装箱号
		        </template>
		       {{form.contaNo}}
		  </el-descriptions-item>
		 <el-descriptions-item>
		        <template slot="label">
		         集装箱重量
		        </template>
		       {{form.contaWt}}
		  </el-descriptions-item>
		 <el-descriptions-item>
		        <template slot="label">
		         集装箱类型
		        </template>
		       {{form.contaType}}
		  </el-descriptions-item>
		 <el-descriptions-item>
		        <template slot="label">
		         集装箱尺寸
		        </template>
		       {{form.contaSize}}
		  </el-descriptions-item>
		 <el-descriptions-item>
		        <template slot="label">
		         集装箱代码
		        </template>
		       {{form.contaCode}}
		  </el-descriptions-item>
		 <el-descriptions-item>
		        <template slot="label">
		         中文集装箱规格名称
		        </template>
		       {{form.cnContaSpec}}
		  </el-descriptions-item>
		 <el-descriptions-item>
		        <template slot="label">
		         申报人
		        </template>
		       {{form.declBy}}
		  </el-descriptions-item>
		 <el-descriptions-item>
		        <template slot="label">
		         申报时间
		        </template>
		       {{form.declTime}}
		  </el-descriptions-item>
		  <el-descriptions-item>
		        <template slot="label">
		         审核状态
		        </template>
		        <dict-tag :options="dict.type.conta_decl_status" :value="form.declStatus"/>
		  </el-descriptions-item>
		 <el-descriptions-item>
		        <template slot="label">
		         申报重试次数，超过3分钟未回执，会自动再次发起申报，超过10次不在重试
		        </template>
		       {{form.declRetryNum}}
		  </el-descriptions-item>
		 <el-descriptions-item>
		        <template slot="label">
		         审核时间
		        </template>
		       {{form.auditDate}}
		  </el-descriptions-item>
		 <el-descriptions-item>
		        <template slot="label">
		         创建者
		        </template>
		       {{form.createBy}}
		  </el-descriptions-item>
		 <el-descriptions-item>
		        <template slot="label">
		         创建时间
		        </template>
		       {{form.createTime}}
		  </el-descriptions-item>
		 <el-descriptions-item>
		        <template slot="label">
		         更新者
		        </template>
		       {{form.updateBy}}
		  </el-descriptions-item>
		 <el-descriptions-item>
		        <template slot="label">
		         更新时间
		        </template>
		       {{form.updateTime}}
		  </el-descriptions-item>
		 <el-descriptions-item>
		        <template slot="label">
		         备注
		        </template>
		       {{form.remark}}
		  </el-descriptions-item>
         </el-descriptions>  
        <div slot="footer" class="dialog-footer" style="text-align: center;">
          <el-button @click="closeDetail">关闭</el-button>
        </div>
    </el-dialog>
  </div>
</template>

<script>
import { listContaRecord, getContaRecord, delContaRecord, addContaRecord, updateContaRecord, exportContaRecord } from "@/api/billsdecl/contaRecord";

export default {
  name: "ContaRecord",
  dicts: ['conta_decl_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
       //详情显示的时候，表单编辑禁用
      isViewDisabled:false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 集装箱备案表格数据
      contaRecordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
       //显示详情
      detailOpen:false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        contaNo: null,
        declStatus: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询集装箱备案列表 */
    getList() {
      this.loading = true;
      listContaRecord(this.queryParams).then(response => {
        this.contaRecordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        fieldCode: null,
        fieldName: null,
        contaNo: null,
        contaWt: null,
        contaType: null,
        contaSize: null,
        contaCode: null,
        cnContaSpec: null,
        declBy: null,
        declTime: null,
        declStatus: null,
        declRetryNum: null,
        auditDate: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.isViewDisabled=false;
      this.open = true;
      this.title = "添加集装箱备案";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      this.load(id);
      this.title = "修改集装箱备案";
      this.open = true;
    },
    //关闭详情
    closeDetail(){
      this.detailOpen=false;
    },
     //显示详情
    showDetail(row, column, event){
        this.reset();
        //关闭表单编辑模式
        this.isViewDisabled=true;
        const id = row.id;
        this.load(id);
          //打开详情
        this.detailOpen=true;
    },
     /** 加载数据 */
    load(id){
	    getContaRecord(id).then(response => {
          this.form = response.data;
                  });
	},
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateContaRecord(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addContaRecord(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除集装箱备案编号为"' + ids + '"的数据项？').then(function() {
        return delContaRecord(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$modal.confirm('是否确认导出所有集装箱备案数据项？').then(() => {
        this.exportLoading = true;
        return exportContaRecord(queryParams);
      }).then(response => {
        this.download(response.msg);
        this.exportLoading = false;
      }).catch(() => {});
    }
  }
};
</script>
<style>
.el-table th>.cell{
  white-space: nowrap; /* 文本在一行显示，不换行 */
  text-overflow: ellipsis; /* 显示省略符号来代表被修剪的文本。*/
  overflow: hidden; /* 超出部分隐藏 */
}
</style>
